package com.ganjingcun.roma.persist.pool;

import com.mchange.v2.c3p0.ComboPooledDataSource;
import org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory;

import java.beans.PropertyVetoException;

/**
 * Created by linus on 16/4/15.
 */
public class C3P0DataSourceFactory extends UnpooledDataSourceFactory {

    public C3P0DataSourceFactory() {
        this.dataSource = new ComboPooledDataSource();

        if(dataSource instanceof ComboPooledDataSource){
            ComboPooledDataSource ds = (ComboPooledDataSource)dataSource;
            try {
                ds.setDriverClass("com.mysql.jdbc.Driver");
            } catch (PropertyVetoException e) {
                e.printStackTrace();
            }
            ds.setInitialPoolSize(10);
            ds.setMinPoolSize(1);
            ds.setMaxPoolSize(100);
            ds.setMaxStatements(50);
            ds.setMaxStatementsPerConnection(100);
            ds.setMaxIdleTime(6000);
            ds.setJdbcUrl("jdbc:mysql://localhost:3306/adserver");
            ds.setUser("root");
            ds.setPassword("tiger");
        }
    }

}
